export const GET_AWARD_LIST = "GET_AWARD_LIST";
export const GET_AWARD_DETAIL = "GET_AWARD_DETAIL";

import { awardList, awardDetail } from "../api/index";

export const getAwardList = dispatch => {
  return async dispatch => {
    let awardListRes = await awardList();
    if (awardListRes.length == 0 || !awardListRes) {
      // 使用测试数据
      awardListRes = testAwardList;
    }
    return dispatch({
      type: "GET_AWARD_LIST",
      awardList: awardListRes
    });
  };
};

export const getAwardDetail = (dispatch, id) => {
  return async dispatch => {
    let awardDetailRes = await awardDetail(id);
    if (!awardDetailRes) {
      // 使用测试数据
      awardDetailRes = testAwardList[0];
    }
    return dispatch({
      type: "GET_AWARD_DETAIL",
      awardDetail: awardDetailRes
    });
  };
};

export const requestPosts = subreddit => ({
  type: REQUEST_POSTS,
  subreddit
});

let testAwardList = [
  {
    id: "5ca5737e623071883cf14e78",
    title: "[小米9活动]",
    tag: "为物优选",
    num: 1,
    state: 2,
    synopsis: "奖品：小米9 x 1",
    desc:
      '<p>6G+128G小米9幻彩蓝全网通一部，中奖后可按官方价折现。</p><p>&nbsp;<br></p><p>参与条件：</p><p>①关注活动方微信公众号"为物优选"&nbsp;</p><p>②转发公众号“为物优选”的最新推文到朋友圈。</p>',
    open: 0,
    img: "https://img.ydhwh.cn/b33d2c745b5b5f40d3f0063b01d87718.jpg",
    startTime: "04月04日 11:01",
    luckyTime: "04月10日 11:01"
  }
];
